package com.lengxf.aPlugins.excel;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;

import java.io.File;
import java.nio.charset.Charset;
import java.util.List;

public class ClassGenerator {

    private static final String prefix = "/Users/lengxf/java/study_code/lengxf-java/a-plugins/src/main/java/com/lengxf/aPlugins/excel/";


    public static void main(String[] args) {
        String readPath = prefix + "1.json";
        String writePath = prefix + "1.txt";

        JSON json3 = JSONUtil.readJSON(new File(readPath), Charset.defaultCharset());
        List<FrontDTO> craftInfoDTOList = JSONUtil.toList(json3.toString(), FrontDTO.class);

        for (FrontDTO frontDTO : craftInfoDTOList) {
            String annotation = String.format("@ExcelProperty(\"%s\")", frontDTO.getLabel());
            FileUtil.appendUtf8String(annotation, writePath);
            FileUtil.appendUtf8String("\n", writePath);
            String field = String.format("private String %s;", frontDTO.getField());
            FileUtil.appendUtf8String(field, writePath);
            FileUtil.appendUtf8String("\n", writePath);
        }
    }


}
